<script type="text/javascript">
function validate_form() {
    <?php
        if(count($this->language) > 0) :
            foreach($this->language as $value) :
    ?>
    if($('#tabs-<?php echo $value['locale'] ?>').hasClass('ui-tabs-hide') == false) {
        var image = $('#image').val();
        var name_<?php echo $value['locale'] ?> = $('#name-<?php echo $value['locale'] ?>').val();
        var schedule_<?php echo $value['locale'] ?> = $('#schedule-<?php echo $value['locale'] ?>').val();
        var start_date_<?php echo $value['locale'] ?> = $('#start_date-<?php echo $value['locale'] ?>').val();
        var price = $('#price').val();
        var price_children = $('#price_children').val();
        var description_<?php echo $value['locale'] ?> = tinyMCE.get('description-<?php echo $value['locale'] ?>').getContent();
        var include_price_<?php echo $value['locale'] ?> = tinyMCE.get('include_price-<?php echo $value['locale'] ?>').getContent();
        var not_include_price_<?php echo $value['locale'] ?> = tinyMCE.get('not_include_price-<?php echo $value['locale'] ?>').getContent();
        var children_<?php echo $value['locale'] ?> = tinyMCE.get('children-<?php echo $value['locale'] ?>').getContent();
        var condition_<?php echo $value['locale'] ?> = tinyMCE.get('condition-<?php echo $value['locale'] ?>').getContent();
        var countError = 0;
        if((name_<?php echo $value['locale'] ?>.length < 1) || (name_<?php echo $value['locale'] ?>.length > 300)) {
            $('#errorName-<?php echo $value['locale'] ?>').html('Tên tour từ 1-300 kí tự');
            countError++;
        }
        else {
            $('#errorName-<?php echo $value['locale'] ?>').html('');
        }
        if(description_<?php echo $value['locale'] ?> == '') {
            $('#errorDescription-<?php echo $value['locale'] ?>').html('Giới thiệu tour không được để trống');
            countError++;
        }
        else {
            $('#errorDescription-<?php echo $value['locale'] ?>').html('');
        }
        if(schedule_<?php echo $value['locale'] ?> == '') {
            $('#errorSchedule-<?php echo $value['locale'] ?>').html('Lịch trình không được để trống');
            countError++;
        }
        else {
            $('#errorSchedule-<?php echo $value['locale'] ?>').html('');
        }
        if(start_date_<?php echo $value['locale'] ?> == '') {
            $('#errorStartDate-<?php echo $value['locale'] ?>').html('Khởi hành không được để trống');
            countError++;
        }
        else {
            $('#errorStartDate-<?php echo $value['locale'] ?>').html('');
        }
        var reg = /^([0-9]{1,6})$/;
        if(reg.test(price) == false) {
            $('#errorPrice').html('Giá người lớn gồm các kí tự số 0-9 và không quá 6 kí tự');
            countError++;
        }
        else {
            $('#errorPrice').html('');
        }
        if(reg.test(price_children) == false) {
            $('#errorPriceChildren').html('Giá trẻ em gồm các kí tự số 0-9 và không quá 6 kí tự');
            countError++;
        }
        else {
            $('#errorPriceChildren').html('');
        }
        if(include_price_<?php echo $value['locale'] ?> == '') {
            $('#errorIncludePrice-<?php echo $value['locale'] ?>').html('Giá tour bao gồm không được để trống');
            countError++;
        }
        else {
            $('#errorIncludePrice-<?php echo $value['locale'] ?>').html('');
        }
        if(not_include_price_<?php echo $value['locale'] ?> == '') {
            $('#errorNotIncludePrice-<?php echo $value['locale'] ?>').html('Giá tour chưa bao gồm không được để trống');
            countError++;
        }
        else {
            $('#errorNotIncludePrice-<?php echo $value['locale'] ?>').html('');
        }
        if(children_<?php echo $value['locale'] ?> == '') {
            $('#errorChildren-<?php echo $value['locale'] ?>').html('Quy định trẻ em không được để trống');
            countError++;
        }
        else {
            $('#errorChildren-<?php echo $value['locale'] ?>').html('');
        }
        if(condition_<?php echo $value['locale'] ?> == '') {
            $('#errorCondition-<?php echo $value['locale'] ?>').html('Điều kiện hủy tour không được để trống');
            countError++;
        }
        else {
            $('#errorCondition-<?php echo $value['locale'] ?>').html('');
        }
        if(!/(\.png|\.gif|\.jpg|\.jpeg\.PNG|\.GIF|\.JPG|\.JPEG)$/i.test(image)) {
            $('#errorImage').html('Ảnh phải đúng định dạng jpg, jpeg, png, gif');
            countError++; 
        }
        else {
            $('#errorImage').html('');
        }
        if(countError > 0) {
            return false;
        }
        else {
            return true;
        }
    }
    <?php
            endforeach;
        endif;
    ?>
};

$(document).ready(function(){
   $('#area_id').change(function(){
        var area_id = $('#area_id').val();
        $.ajax({ 
            url: "<?php echo $this->url(array('module'=>'admincp','controller'=>'tour','action'=>'loadlocation'));?>", 
            type: "post",
            data: "parent="+area_id,
            cache: false,
            async :false,
            success :function(string) {
            	$('#location_id').html(string);
            }
        });
   });
   
   var area_id = $('#area_id').val();
   $.ajax({ 
       url: "<?php echo $this->url(array('module'=>'admincp','controller'=>'tour','action'=>'loadlocation'));?>", 
       type: "post",
       data: "parent="+area_id,
       cache: false,
       async :false,
       success :function(string) {
           $('#location_id').html(string);
       }
   });
});
</script>
<div class="list_category">
        <ul>
            <li><a href="<?php echo $this->baseUrl('admincp/tour'); ?>">Quản lý tour</a></li>
        </ul>
    </div>
</div>

<!-- Begin Content -->
<div class="section">
    <div class="heading_section">
        <span>Tạo tour mới</span>
    </div>

    <div class="content">
    <form action="" method="post" onsubmit="return validate_form()" enctype="multipart/form-data">
        <div id="tabs">
            <ul>
                <?php
                    if(count($this->language) > 0) :
                        foreach($this->language as $value) :
                ?>
                    <li><a href="#tabs-<?php echo $value['locale']; ?>"><?php echo $value['name']; ?></a></li>
                <?php
                        endforeach;
                    endif;
                ?>
            </ul>
            
            <?php
                if(count($this->language) > 0) :
                    foreach($this->language as $value) :
            ?>
            <div id="tabs-<?php echo $value['locale']; ?>">
                <table class="table">
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('name-'.$value['locale'],'Tiêu đề tour'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formText('name-'.$value['locale'],null,array('class'=>'input','style'=>'width:295px')); ?></td>
                        <td class="td3" id="errorName-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('schedule-'.$value['locale'],'Lịch trình'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formText('schedule-'.$value['locale'],null,array('class'=>'input','style'=>'width:295px')); ?></td>
                        <td class="td3" id="errorSchedule-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('start_date-'.$value['locale'],'Khởi hành'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formText('start_date-'.$value['locale'],null,array('class'=>'input','style'=>'width:295px')); ?></td>
                        <td class="td3" id="errorStartDate-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('description-'.$value['locale'],'Giới thiệu tour'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formTextarea('description-'.$value['locale'],null,array('class'=>'ckeditor','style'=>'height: 100px;')); ?></td>
                        <td class="td3" id="errorDescription-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('include_price-'.$value['locale'],'Giá tour bao gồm'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formTextarea('include_price-'.$value['locale'],null,array('class'=>'ckeditor','style'=>'height: 100px;')); ?></td>
                        <td class="td3" id="errorIncludePrice-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('not_include_price-'.$value['locale'],'Giá tour chưa bao gồm'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formTextarea('not_include_price-'.$value['locale'],null,array('class'=>'ckeditor','style'=>'height: 100px;')); ?></td>
                        <td class="td3" id="errorNotIncludePrice-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('children-'.$value['locale'],'Quy định trẻ em'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formTextarea('children-'.$value['locale'],null,array('class'=>'ckeditor','style'=>'height: 100px;')); ?></td>
                        <td class="td3" id="errorChildren-<?php echo $value['locale']; ?>"></td>
                    </tr>
                    <tr>
                        <td class="td1"><?php echo $this->formLabel('condition-'.$value['locale'],'Điều kiện hủy tour'); ?>&nbsp;<span class="error-msg">*</span></td>
                        <td class="td2"><?php echo $this->formTextarea('condition-'.$value['locale'],null,array('class'=>'ckeditor')); ?></td>
                        <td class="td3" id="errorCondition-<?php echo $value['locale']; ?>"></td>
                    </tr>
                </table>
            </div>
            <?php
                    endforeach;
                endif;
            ?>
            
            <table class="table">
                <tr>
                    <td class="td1"><?php echo $this->formLabel('price','Giá người lớn'); ?>&nbsp;<span class="error-msg">*</span></td>
                    <td class="td2"><?php echo $this->formText('price',null,array('class'=>'input','style'=>'width:79%')); ?> 000đ</td>
                    <td class="td3" id="errorPrice"></td>
                </tr>
                <tr>
                    <td class="td1"><?php echo $this->formLabel('price_children','Giá trẻ em'); ?>&nbsp;<span class="error-msg">*</span></td>
                    <td class="td2"><?php echo $this->formText('price_children',null,array('class'=>'input','style'=>'width:79%')); ?> 000đ</td>
                    <td class="td3" id="errorPriceChildren"></td>
                </tr>
                <tr>
                    <td class="td1"><?php echo $this->formLabel('image', 'Ảnh tour'); ?>&nbsp;<span class="error-msg">*</span></td>
                    <td class="td2"><input type="file" name="image" id="image" /></td>
                    <td class="td3" id="errorImage"></td>
                </tr>
                <tr>
                    <td class="td1"><?php echo $this->formLabel('category_id', 'Danh mục'); ?></td>
                    <td class="td2">
                        <select name="category_id" id="category_id" class="selectbox">
                        <?php
                            if(count($this->category) > 0) :
                                foreach($this->category as $value) :
                        ?>
                            <option value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
                        <?php
                            endforeach;
                            endif;
                        ?>
                        </select>
                    </td>
                    <td class="td3"></td>
                </tr>
                <tr>
                    <td class="td1"><?php echo $this->formLabel('area_id', 'Vùng miền'); ?></td>
                    <td class="td2">
                        <select name="area_id" id="area_id" class="selectbox">
                        <?php
                            if(count($this->location) > 0) :
                                foreach($this->location as $value) :
                        ?>
                            <option value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
                        <?php
                            endforeach;
                            endif;
                        ?>
                        </select>
                    </td>
                    <td class="td3"></td>
                </tr>
                <tr>
                    <td class="td1"><?php echo $this->formLabel('location_id', 'Tỉnh thành phố'); ?></td>
                    <td class="td2">
                        <select name="location_id" id="location_id" class="selectbox">
                        
                        </select>
                    </td>
                    <td class="td3"></td>
                </tr>
                <tr>
                    <td class="td1">&nbsp;</td>
                    <td class="td2">
                        <?php echo $this->formSubmit('submit','Chấp nhận',array('class'=>'button')); ?>
                        <?php echo $this->formReset('reset','Nhập lại',array('class'=>'button')); ?>
                    </td>
                    <td class="td3"></td>
                </tr>
            </table>
        </div>
    </form>
    </div>
</div>
<!-- End Content -->